package com.baibei.order.bill.querymoney;

import android.content.Context;
import android.util.Log;

import com.baibei.basic.BasicPresenterImpl;
import com.baibei.basic.module.observer.PageDataObservable;
import com.baibei.basic.module.observer.PageObservable;
import com.baibei.ebec.sdk.ApiFactory;
import com.baibei.ebec.sdk.IOrderApi;
import com.baibei.model.PaymentRecordInfo;

import java.util.List;

import io.reactivex.Observable;

/**
 * 表现层实现
 * Created by shenminjie on 2017/8/21.
 * mail:shenminjie@100bei.com
 */

public class PaymentPickUpRecordPresenterImpl extends BasicPresenterImpl<PaymentPickUpRecordContract.PaymentPickUpRecordView>
        implements PaymentPickUpRecordContract.Presenter {

    private IOrderApi mOrderApi;
    private PageObservable<PaymentRecordInfo> mPageObservable;

    public PaymentPickUpRecordPresenterImpl(Context context, PaymentPickUpRecordContract.PaymentPickUpRecordView view) {
        super(context, view);
        mOrderApi = ApiFactory.getInstance().getOrderApi();
        mPageObservable = new PageDataObservable<PaymentRecordInfo>(mView) {
            @Override
            protected Observable<List<PaymentRecordInfo>> onCreateObserver(int page) {
                Observable<List<PaymentRecordInfo>> observable = createObservable(mOrderApi.getMoneyLogList(page));

                return observable;
            }

            @Override
            protected void onLoadDataComplete(List<PaymentRecordInfo> dataList) {
                super.onLoadDataComplete(dataList);
                mView.hideRefreshLayout();
            }

            @Override
            protected void onNoMoreData() {
                super.onNoMoreData();
                mView.hideRefreshLayout();
            }
        };
    }


    @Override
    public void start() {
        super.start();
        mPageObservable.start();
    }

    @Override
    public void loadMore() {
        mPageObservable.loadMore();
    }
}
